package com.celan.year2023.month05.day02;

import java.util.*;

/**
 * @author Celan
 * @ClassName Solution
 * @description: TODO
 * @date 2023/05/02
 * @version: 1.0
 */
class Solution {
    public List<Integer> powerfulIntegers(int x, int y, int bound) {
        Set<Integer> ans = new HashSet<>();
        for (int a = 1; a <= bound; a *= x) {
            for (int b = 1; a + b <= bound; b *= y) {
                ans.add(a + b);
                if (y == 1) {
                    break;
                }
            }
            if (x == 1) {
                break;
            }
        }
        return new ArrayList<>(ans);
    }
}